package com.binarytree;

public class Solution23 {

    public boolean isValidBST(TreeNode root) {
        return check(Long.MIN_VALUE,Long.MAX_VALUE,root);
    }

    public boolean check(long low, long high,TreeNode root) {
        if (root == null) return true;
        if (root.val <= low || root.val >= high) return false;
        return check(low,root.val,root.left) && check(root.val,high,root.right);
    }

}
